package com.ymatou.auth.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.IpAreaAuthStatusRequestDtoBean;
import com.ymatou.auth.parameter.LoginAuthBean;
import com.ymatou.auth.service.IpAreaAuthStatusRequestDtoCall;
import com.ymatou.auth.service.LoginAuthCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.data.LoginSafeConfiguration;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.mongo.MongoLoginHistoryWapper;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.database.mongo.YmatouBlacklistUserWapper;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
*PC端IP区域认证接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IpAreaAuthStatusRequestDto{
	private static IpAreaAuthStatusRequestDtoBean ipareaauthstatusrequestdtoBean;
	private static IpAreaAuthStatusRequestDtoCall ipareaauthstatusrequestdtoCall;
	private static ULC201406Wapper userWapper;
	private static YmatouBlacklistUserWapper blackLisWapper;
	private static UserSafeWapper authWapper;
	private static final String SOURCETYPE = "mainsite";
	private static MongoLoginHistoryWapper mloginHistoryWapper;
	private static final boolean DELETELOGINHISTORY = true;
	
	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("PC端IP区域认证接口");
		
	}

	@Before
	public void caseUp() throws Exception {
		ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
		ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
		userWapper = new ULC201406Wapper();
		blackLisWapper = new YmatouBlacklistUserWapper();
		authWapper=new UserSafeWapper();
		mloginHistoryWapper = new MongoLoginHistoryWapper();
	}

	@AfterClass
	public static void tearDown() throws Throwable {
		Logger.generateResult(ipareaauthstatusrequestdtoCall.getOpurl());
		userWapper.close();
		blackLisWapper.close();
		authWapper.close();
		mloginHistoryWapper.close();
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	//第一次登入如果是已经认证过的，现在成功
	public void Tc_IpAreaAuthStatusRequestDto_001() {
		Logger.start(true,"IP第一次登陆后再次认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = "001.014.191.25"+new Random().nextInt(9);//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			
			Logger.comment("如果此IP已认证过，先进行删除");
			authWapper.deleteIPAreaData(userId, "China", "Shanghai", "Shanghai");
			
			Logger.comment("IP区域登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_PC_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			LoginSafeConfiguration.checkAuthStatus(true, ipareaauthstatusrequestdtoCall);
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Thread.sleep(1000);
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> ipAuth2 = authWapper.getIPAuthByUserIdAndArea(userId, "China", "Shanghai", "Shanghai");
			Logger.verifyEquals(200, ipAuth2.get("AuthStatus"), "验证认证信息成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_IpAreaAuthStatusRequestDto_002() {
		Logger.start(true,"使用Token失效的IP登陆，再次认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = "001.014.191.254";//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			checkIpLoginHistory(ip,YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("修改token最后认证时间为100天前");
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			authWapper.updateTokenUpdateTime(userId, null, null, null, YMTDateUtil.getBeforeOrNextDay(-100));
			
			Logger.comment("登陆");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			
			Logger.comment("认证失败");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();
			authWapper.updateTokenUpdateTime(userId,null,null, null, YMTDateUtil.getBeforeOrNextDay(-10));
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> ipAuth2 = authWapper.getIPAuthByUserIdAndArea(userId, null, null, null);
			Logger.verifyEquals(200, ipAuth2.get("AuthStatus"), "验证认证信息成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_IpAreaAuthStatusRequestDto_003() {
		Logger.start(true,"黑名单IP第一次认证失败后，再次认证成功");
		try {
			Logger.debug("注册用户");
			List<Map> maps=new ArrayList<>();
			String ip = TestDataManager.getRandomIp(); 
			for(int i=0;i<11;i++){
				String email=TestDataManager.getEmail();
				String phone=TestDataManager.getPhoneNum();
				Map m=UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			Logger.debug("登入用户触发ip黑名单");
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab=new LoginAuthBean();
				lac=new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId());
				lab.setPas("1234561");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map m=UserCallService.registerUser(email, phone, null);
			Logger.debug("测试用户触发ip黑名单");
			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			lab=new LoginAuthBean();
			lac=new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(phone);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(false);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			LoginSafeConfiguration.checkAuthStatus(false, ipareaauthstatusrequestdtoCall);
			
			lab=new LoginAuthBean();
			lac=new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(phone);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			LoginSafeConfiguration.checkAuthStatus(true, ipareaauthstatusrequestdtoCall);
						
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> ipAuth2 = authWapper.getIPAuthByUserIdAndArea(userId, null, null, null);
			Logger.verifyEquals(200, ipAuth2.get("AuthStatus"), "验证认证信息成功");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_IpAreaAuthStatusRequestDto_004() {
		Logger.start(true, "按配置类型判断是否让用户执行安全流程:www.ymatou.com,mainsite,app,check_usertype_0");
		try {
			List<Map> maps=new ArrayList<>();
			String ip = TestDataManager.getRandomIp(); 
			for(int i=0;i<11;i++){
				String email=TestDataManager.getEmail();
				String phone=TestDataManager.getPhoneNum();
				Map m=UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			Logger.comment("添加IP黑名单");
			LoginAuthBean lab=new LoginAuthBean();
			LoginAuthCall lac=new LoginAuthCall();
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab=new LoginAuthBean();
				lac=new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId());
				lab.setPas("1234561");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map m=UserCallService.registerUser(email, phone, null);
			
			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			String loginId = user.getlBills().getLoginId();
			
			Logger.comment("登陆");
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType("www.ymatou.com");
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, false, null);
						
			Logger.comment("认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			LoginSafeConfiguration.checkAuthStatus(true, ipareaauthstatusrequestdtoCall);
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//第一次登入如果是已经认证过的，现在成功
	public void Tc_IpAreaAuthStatusRequestDto_005() {
		Logger.start(true,"传入TokenSource为app用户注册成功JIRACONN-2123");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			int n=new Random().nextInt(20)+200;
			String ip = "001.014.191."+n;//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			
			Logger.comment("如果此IP已认证过，先进行删除");
			authWapper.deleteIPAreaData(userId, "China", "Shanghai", "Shanghai");
			
			Logger.comment("IP区域登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_PC_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoBean.setTokenSource("app");
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			LoginSafeConfiguration.checkAuthStatus(true, ipareaauthstatusrequestdtoCall);
			String Sign=ipareaauthstatusrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("UserData").getAsJsonObject().get("Sign").getAsString();
//			Logger.verifyEquals(128, Sign.length(), "TokenSource验证Sign长度为128");
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lab.setTokenSource("app");
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Thread.sleep(1000);
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> ipAuth2 = authWapper.getIPAuthByUserIdAndArea(userId, "China", "Shanghai", "Shanghai");
			Logger.verifyEquals(200, ipAuth2.get("AuthStatus"), "验证认证信息成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//第一次登入如果是已经认证过的，现在成功
	public void Tc_IpAreaAuthStatusRequestDto_006() {
		Logger.start(true,"双重认证开启IP认证成功JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = "001.014.191.255";//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			
			Logger.comment("如果此IP已认证过，先进行删除");
			authWapper.deleteIPAreaData(userId, "China", "Shanghai", "Shanghai");
			
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("IP区域登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_PC_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoBean.setVerifySecurityQuestion(true);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("true", lac3.getString("Success"), "验证登陆成功");
			
			Thread.sleep(1000);
			Logger.comment("验证认证数据已写进数据库");
			Map<String, Object> ipAuth2 = authWapper.getIPAuthByUserIdAndArea(userId, "China", "Shanghai", "Shanghai");
			Logger.verifyEquals(200, ipAuth2.get("AuthStatus"), "验证认证信息成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	//第一次登入如果是已经认证过的，现在成功
	public void Tc_IpAreaAuthStatusRequestDto_007() {
		Logger.start(true,"双重认证开启VerifySecurityQuestion未传IP认证失败JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = "001.014.191.255";//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			
			Logger.comment("如果此IP已认证过，先进行删除");
			authWapper.deleteIPAreaData(userId, "China", "Shanghai", "Shanghai");
			
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("IP区域登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_PC_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("false", lac3.getString("Success"), "验证登陆成功");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_IpAreaAuthStatusRequestDto_008() {
		Logger.start(true,"双重认证开启VerifySecurityQuestion传falseIP认证失败JIRACONN-2522");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = "001.014.191.255";//china, shanghai, shanghai
			Map UserMap = UserCallService.registerUser(email, phone,ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String loginId = (String) UserMap.get("loginId");
			
			Logger.comment("如果此IP已认证过，先进行删除");
			authWapper.deleteIPAreaData(userId, "China", "Shanghai", "Shanghai");
			
			AuthCallService.setSecurityQuestion(userId);
			AuthCallService.setSecurity(userId, true);
			
			Logger.comment("IP区域登陆，当前设备认证状态是:"+LoginSafeConfiguration.AUTH_PC_OPEN+"(打开则会登陆失败，关闭则登陆成功)");
			LoginAuthBean lab = new LoginAuthBean();
			LoginAuthCall lac = new LoginAuthCall();
			lab.setLoginId(loginId);
			lab.setClientIp(ip);
			lab.setSourceType(SOURCETYPE);
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			
			Logger.comment("登陆");
			LoginAuthCall lac2 = new LoginAuthCall();
			lac2.setData(lab);
			lac2.callService();
			
			Logger.comment("开始第二次认证成功");
			ipareaauthstatusrequestdtoBean=new IpAreaAuthStatusRequestDtoBean();
			ipareaauthstatusrequestdtoCall=new IpAreaAuthStatusRequestDtoCall();
			ipareaauthstatusrequestdtoBean.setIp(ip);
			ipareaauthstatusrequestdtoBean.setLoginId(loginId);
			ipareaauthstatusrequestdtoBean.setPassword("123456a");
			ipareaauthstatusrequestdtoBean.setSuccess(true);
			ipareaauthstatusrequestdtoBean.setSource(SOURCETYPE);
			ipareaauthstatusrequestdtoBean.setVerifySecurityQuestion(false);
			ipareaauthstatusrequestdtoCall.setData(ipareaauthstatusrequestdtoBean);
			ipareaauthstatusrequestdtoCall.callService();	
			
			Logger.comment("登陆");
			LoginAuthCall lac3 = new LoginAuthCall();
			lac3.setData(lab);
			lac3.callService();
			Logger.verifyEquals("false", lac3.getString("Success"), "验证登陆成功");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	public void checkIpLoginHistory(String ip, String dateTime) throws Exception{
		if(DELETELOGINHISTORY){
			blackLisWapper.deleteData(ip);
			mloginHistoryWapper.deleteByIp(ip, dateTime);
		}
	}
}